package com.longge.wechat.socket;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class TestClient {
	public static void main(String[] args) {
		InputStream is = null;
		OutputStream os = null;
		try {
			Socket s = new Socket("localhost", 6666);
			is = s.getInputStream();
			os = s.getOutputStream();
			DataInputStream dis = new DataInputStream(is);
			DataOutputStream dos = new DataOutputStream(os);
			dos.writeUTF("我要请求连接");
			String str = null;
			if((str = dis.readUTF()) != null) {
				System.out.println("收到内容是："+str);
			}
			dos.close();
			dis.close();
			s.close();
		} catch (UnknownHostException e) {
			e.printStackTrace();
			System.out.println("主机不存在");
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("请求失败");
		}
	}
}
